package com.dk.controller;

import com.dk.pojo.Position;
import com.dk.service.PosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 权限级别
 */
@Controller
@RequestMapping("pos")
public class PosController {
    @Autowired
    private PosService posService;

    @RequestMapping("toShow")
    public String toShow(){
        return "/pos/show";
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public List<Position> getInfo(){
        return posService.getInfo();
    }

    @RequestMapping("toAdd")
    public String toAdd(){
        return "/pos/add";
    }

    @RequestMapping("toUpdate/{positionId}")
    public String toUpdate(@PathVariable("positionId")Integer positionId, Model model){
        Position position = posService.toUpdate(positionId);
        model.addAttribute("position",position);
        return "/pos/update";
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public boolean addInfo(Position position,@RequestParam("nodeIds")Integer[] nodeIds){
        return posService.addInfo(position,nodeIds);
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(Position position,@RequestParam("nodeIds")Integer[] nodeIds){
        return posService.updateInfo(position,nodeIds);
    }

    @RequestMapping("deleteInfo/{id}")
    @ResponseBody
    public boolean deleteInfo(@PathVariable("id")Integer id){
        return posService.deleteInfo(id);
    }

}
